package xstr

import (
	"math/rand"
	"strings"
)

type AESType int

const (
	AES128 AESType = 128
	AES256 AESType = 256

	CHARS string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)

// GenerateAESKeyWithType ... 生成AES key
func GenerateAESKeyWithType(aesType AESType) string {

	var total = 16
	if aesType == AES256 {
		total = 32
	}

	var builder strings.Builder
	var i int
	for i = 0; i < total; i++ {
		index := rand.Intn(len(CHARS))
		builder.WriteString(CHARS[index : index+1])
	}

	return builder.String()
}

// GenerateAESIv 生成偏移量 固定为16位
func GenerateAESIv() string {
	return GenerateAESKeyWithType(AES128)
}

// GenerateAESKey ... 生成AES key
func GenerateAESKey() string {
	return GenerateAESKeyWithType(AES128)
}
